import {emitter} from './core.es6.js';

//
// 杂类函数
//


/**
 * 运行时间测试
 * @param  {String} name 测试名称
 * @return {Emitter}
 */
export const benchmark = (name) => {

  let
    marker = {},
    emt = emitter(marker),
    print = '',
    now = () => { return new Date().getTime() };

  marker[name] = {
    point: {}, start: now()
  };
  emt.on('set', (point) => {
    marker[name].point[point] = now() - marker[name].start;
    marker[name].start = now();
  });
  emt.on('print', () => {
    print = name;
    for(let p in marker[name].point){
      print += `${p}: ${marker[name].point[p]} ms | `;
    }
    print = print.slice(0, -2);
    window.console && window.console.info(print);
  });

  return emt;

};
